package com.service.weChatWifiLogin.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.service.config.utils.*;
import com.service.weChatWifiLogin.dao.CustomerOrBossDao;
import com.service.weChatWifiLogin.dao.ScanRecordDao;
import com.service.weChatWifiLogin.dao.ShopInfoDao;
import com.service.weChatWifiLogin.dao.ShopInfoReviewDao;
import com.service.weChatWifiLogin.dto.*;
import com.service.weChatWifiLogin.entity.*;
import com.service.weChatWifiLogin.service.CustomerOrBossService;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.*;

import static com.service.config.constant.ApiUrlConstants.*;
import static com.service.config.constant.Constant.*;
import static com.service.weChatWifiLogin.utile.MD5Util.getCharAndNumr;

/**
 * 顾客/boss全局表(CustomerOrBoss)表服务实现类
 *
 * @author makejava
 * @since 2021-06-16 17:10:22
 */
@Service("customerOrBossService")
public class CustomerOrBossServiceImpl implements CustomerOrBossService {
    @Resource
    private CustomerOrBossDao customerOrBossDao;
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private ShopInfoDao shopInfoDao;
    @Resource
    QueryWeiChatServiceImpl queryWeiChatService;
    @Resource
    private ShopInfoReviewDao shopInfoReviewDao;
    @Resource
    ScanRecordDao scanRecordDao;


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CustomerOrBoss queryById(String id) {
        return this.customerOrBossDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CustomerOrBoss> queryAllByLimit(int offset, int limit) {
        return this.customerOrBossDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param customerOrBoss 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerOrBoss insert(CustomerOrBoss customerOrBoss) {
        this.customerOrBossDao.insert(customerOrBoss);
        return customerOrBoss;
    }

    /**
     * 修改数据
     *
     * @param customerOrBoss 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerOrBoss update(CustomerOrBoss customerOrBoss) {
        this.customerOrBossDao.update(customerOrBoss);
        return this.queryById(customerOrBoss.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.customerOrBossDao.deleteById(id) > 0;
    }

    /**
     * boss注册新店铺
     * @param bossRegisterDto
     * @return
     */
    @Override
    @Transactional
    public Result addWeiUser(BossRegisterDto bossRegisterDto) throws Exception {
        HashMap map = new HashMap();
        if ("1".equals(bossRegisterDto.getFlag())) {
            HashMap openId = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(bossRegisterDto.getCode(), "", BOSS_APP_ID, BOSS_SECRET));
            if (openId.containsKey("errcode")){
                return Result.ok().setData(openId);
            }
            Map<String, Object> map2 = JsonXMLUtils.json2map(openId.get("weiChatDto").toString());
            WeiChatDto weiChatDto2 = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
            CustomerOrBoss customerOrBoss = customerOrBossDao.queryByOpenId(weiChatDto2.getOpenid());
            if (customerOrBoss == null) {
                CustomerOrBoss customerOrBoss1 = new CustomerOrBoss();
                customerOrBoss1.setId(IdUtil.getStringId());
                customerOrBoss1.setScanCount(1);
                if (bossRegisterDto.getPhone() != null && !bossRegisterDto.getPhone().equals("")) {
                    if (!RegexUtil.isMobileSimple(bossRegisterDto.getPhone())) {
                        return Result.failure("手机号格式错误，请重新校验");
                    }
                    customerOrBoss1.setTelphone(bossRegisterDto.getPhone());
                }
                customerOrBoss1.setOpenId(weiChatDto2.getOpenid());
                customerOrBoss1.setSessionKey(weiChatDto2.getSession_key());
                customerOrBoss1.setAddtime(new Date());
                customerOrBoss1.setUpdatetime(new Date());
                customerOrBoss1.setSuccesCount(1);
                if (bossRegisterDto.getNickName() != null) {
                    customerOrBoss1.setNickName(bossRegisterDto.getNickName());
                }
                int insert = customerOrBossDao.insert(customerOrBoss1);
                if (insert > 0) {
                    ShopInfo shopInfo = new ShopInfo();
                    ShopInfo shopInfo1 = addShopInfo(customerOrBoss1, shopInfo);
                    List<ShopInfo> shopInfos = new ArrayList<>();
                    shopInfos.add(shopInfo1);
                    String s = UserTokenManager.generateToken(customerOrBoss1.getId());// 新增用户
                    map.put("Token",s);
                    map.put("bossId",customerOrBoss1.getId());
                    redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss1),30);
                    return Result.ok().setData(map);
                }
            }else {
                if (bossRegisterDto.getPhone() != null && !bossRegisterDto.getPhone().equals("")) {
                    if (!RegexUtil.isMobileSimple(bossRegisterDto.getPhone())) {
                        return Result.failure("手机号格式错误，请重新校验");
                    }
                    customerOrBoss.setTelphone(bossRegisterDto.getPhone());
                }
                customerOrBoss.setUpdatetime(new Date());
                customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
                if (bossRegisterDto.getNickName() != null) {
                    customerOrBoss.setNickName(bossRegisterDto.getNickName());
                }
                customerOrBossDao.update(customerOrBoss);
                ShopInfo shopInfo = new ShopInfo();
                shopInfo.setCustomerOrBossId(customerOrBoss.getId());
                shopInfo.setStatus(false); // 店铺未删除
                List<ShopInfo> shopInfos = shopInfoDao.queryAll(shopInfo); // 查出符合老板名下的店铺
                if (shopInfos !=null && shopInfos.size()>0) {
                    String s = UserTokenManager.generateToken(customerOrBoss.getId());// 新增用户
                    map.put("Token",s);
                    map.put("bossId",customerOrBoss.getId());
                    redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss),30);
                    return Result.ok().setData(map);
                }else {
                    addShopInfo(customerOrBoss, shopInfo); // 新增店铺
                    String s = UserTokenManager.generateToken(customerOrBoss.getId());// 新增用户
                    map.put("Token",s);
                    map.put("bossId",customerOrBoss.getId());
                    redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss),30);
                    return Result.ok().setData(map);
                }
            }
        }
        return Result.failure(CODE_EXPIRE,CODE_DESCRIBS);
    }

    /**
     * 解密数据获取用户手机号
     * @param code
     * @param encryptedData
     * @param iv
     * @param flag
     * @return
     * @throws Exception
     */
    @Override
    public Result decrypt(String code, String encryptedData, String iv,String flag) throws Exception {
        String value = redisUtil.getValue(code);
        Map<String, Object> map = JsonXMLUtils.json2map(value);
        WeiChatDto weiChatDto = ModelMapperUtil.strictMap(map, WeiChatDto.class);
        String session_key = weiChatDto.getSession_key();
        String s = com.service.weChatWifiLogin.utile.AESCBCUtil.decrypt(encryptedData,session_key, iv,"utf-8");
        WeiChatPhoneNumberDto weiChatPhoneNumberDto = ModelMapperUtil.strictMap(s, WeiChatPhoneNumberDto.class);
        map.put("errorMsg","code码已失效，请重新获取code");
        return Result.ok().setData(map);
    }

    @Override
    public Result queryCode1(String bAuthToken, String code, String flag,String nickName) throws Exception {
        HashMap map = new HashMap();
        if (bAuthToken == null || bAuthToken.equals("")) {
            if (flag.equals("1")){ // boss端
                return bossResultNoToken(map,bAuthToken,code,flag,nickName);
            }
            if (flag.equals("2")) {
                return customerResultNoToken(map,bAuthToken,code,flag,nickName);
            }
        }else {
            if (flag.equals("1")) {
                return bossResultToken(map,bAuthToken,code,flag,nickName);
            }
            if (flag.equals("2")) {
                if (redisUtil.exist(bAuthToken)) {
                    return customerResultToken(map,bAuthToken,code,flag,nickName);
                }else {
                    return customerResultTokenExpire(map,bAuthToken,code,flag,nickName);
                }
            }
        }
        return Result.ok();
    }

    /**
     * token 缓存过期
     * @param map
     * @param bAuthToken
     * @param code
     * @param flag
     * @param nickName
     * @return
     * @throws Exception
     */
    private Result customerResultTokenExpire(HashMap map, String bAuthToken, String code, String flag, String nickName) throws Exception {
        HashMap map1 = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(code, "", CUSTOMER_APP_ID, CUSTOMER_SECRET)); // 查询微信用户
        if (map1.containsKey("errcode")){
            return Result.ok().setData(map1);
        }
        Map<String, Object> map2 = JsonXMLUtils.json2map(map1.get("weiChatDto").toString());
        WeiChatDto weiChatDto2 = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
        CustomerOrBoss customerOrBoss = customerOrBossDao.queryByOpenId(weiChatDto2.getOpenid());
        if (customerOrBoss!= null) {
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
            customerOrBoss.setTransactionalId(scanRecord.getId());
            customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
            customerOrBoss.setSessionKey(weiChatDto2.getSession_key());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss.setNickName(nickName);
            }
            customerOrBoss.setUpdatetime(new Date());
            customerOrBossDao.update(customerOrBoss);
            redisUtil.set(bAuthToken,5,JsonXMLUtils.obj2json(customerOrBoss),30);
            map.put("Token",bAuthToken);
            return Result.ok().setData(map);
        }else {
            CustomerOrBoss customerOrBoss1 = new CustomerOrBoss();
            customerOrBoss1.setOpenId(weiChatDto2.getOpenid());
            customerOrBoss1.setSessionKey(weiChatDto2.getSession_key());
            customerOrBoss1.setId(IdUtil.getStringId());
            customerOrBoss1.setAddtime(new Date());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss1.setNickName(nickName);
            }
            customerOrBoss1.setUpdatetime(new Date());
            customerOrBoss1.setScanCount(1);
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss1.getId(), null); // 增加扫码记录
            customerOrBoss1.setTransactionalId(scanRecord.getId());
            customerOrBossDao.insert(customerOrBoss1);
            String s = UserTokenManager.generateToken(customerOrBoss1.getId());// 新增用户
            redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss1),30);
            map.put("Token",s);
            return Result.ok().setData(map);
        }
    }

    /**
     * token 缓存未过期
     * @param map
     * @param bAuthToken
     * @param code
     * @param flag
     * @param nickName
     * @return
     * @throws Exception
     */
    private Result customerResultToken(HashMap map, String bAuthToken, String code, String flag, String nickName) throws Exception {
        CustomerOrBoss customerOrBoss = JsonXMLUtils.json2obj(redisUtil.getValue(bAuthToken), CustomerOrBoss.class);
        customerOrBoss = customerOrBossDao.queryById(customerOrBoss.getId());
        ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
        customerOrBoss.setTransactionalId(scanRecord.getId());
        customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
        if (nickName != null && !"".equals(nickName)) {
            customerOrBoss.setNickName(nickName);
        }
        customerOrBoss.setUpdatetime(new Date());
        customerOrBossDao.update(customerOrBoss);
        redisUtil.delete(bAuthToken);
        redisUtil.set(bAuthToken,5,JsonXMLUtils.obj2json(customerOrBoss),30);
        map.put("Token",bAuthToken);
        return Result.ok().setData(map);
    }

    /**
     * boss端token
     * @param map
     * @param bAuthToken
     * @param code
     * @param flag
     * @param nickName
     * @return
     * @throws Exception
     */
    private Result bossResultToken(HashMap map, String bAuthToken, String code, String flag, String nickName) throws Exception {
        if (redisUtil.exist(bAuthToken)) {
            CustomerOrBoss customerOrBoss = JsonXMLUtils.json2obj(redisUtil.getValue(bAuthToken), CustomerOrBoss.class);
            customerOrBoss = customerOrBossDao.queryById(customerOrBoss.getId());
            if (customerOrBoss.getSuccesCount() != null) {
                customerOrBoss.setSuccesCount(customerOrBoss.getSuccesCount()+1);
            }else {
                customerOrBoss.setSuccesCount(1);
            }
            customerOrBoss.setUpdatetime(new Date());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss.setNickName(nickName);
            }
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
            customerOrBoss.setTransactionalId(scanRecord.getId());
            customerOrBossDao.update(customerOrBoss);
            redisUtil.set(bAuthToken,5,JsonXMLUtils.obj2json(customerOrBoss),30);
            map.put("bossId",customerOrBoss.getId());
            map.put("Token",bAuthToken);
            return Result.ok().setData(map);
        }else {
            HashMap openId = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(code, "", BOSS_APP_ID, BOSS_SECRET));
            if (openId.containsKey("errcode")){
                return Result.ok().setData(openId);
            }
            Object weiChatDto1 = openId.get("weiChatDto");
            Map<String, Object> map2 = JsonXMLUtils.json2map(weiChatDto1.toString());
            WeiChatDto weiChatDto2 = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
            CustomerOrBoss customerOrBoss = customerOrBossDao.queryByOpenId(weiChatDto2.getOpenid());
            if (customerOrBoss  != null) {
                customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
                customerOrBoss.setSessionKey(weiChatDto2.getSession_key());
                customerOrBoss.setUpdatetime(new Date());
                if (nickName != null && !"".equals(nickName)) {
                    customerOrBoss.setNickName(nickName);
                }
                ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
                customerOrBoss.setTransactionalId(scanRecord.getId());
                customerOrBossDao.update(customerOrBoss);
                map.put("bossId",customerOrBoss.getId());
                redisUtil.set(bAuthToken,5,JsonXMLUtils.obj2json(customerOrBoss),30);
                map.put("Token",bAuthToken);
                return Result.ok().setData(map);
            }else {
                map.put("errorMsg","用户未注册");
                map.put("code",USER_NOT_FOUND);
                return Result.ok().setData(map);
            }
        }
    }

    /**
     * 顾客端无token
     * @param map
     * @param bAuthToken
     * @param code
     * @param flag
     * @param nickName
     * @return
     * @throws Exception
     */
    private Result customerResultNoToken(HashMap map,String bAuthToken, String code, String flag, String nickName) throws Exception {
        // 顾客端
        HashMap map1 = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(code, "", CUSTOMER_APP_ID, CUSTOMER_SECRET));
        if (map1.containsKey("errcode")){
            return Result.ok().setData(map1);
        }
        Map<String, Object> map2 = JsonXMLUtils.json2map(map1.get("weiChatDto").toString());
        WeiChatDto weiChatDto = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
        CustomerOrBoss customerOrBoss1 = customerOrBossDao.queryByOpenId(weiChatDto.getOpenid());
        if (customerOrBoss1 != null) {
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss1.getId(), null); // 增加扫码记录
            customerOrBoss1.setSessionKey(weiChatDto.getSession_key());
            customerOrBoss1.setUpdatetime(new Date());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss1.setNickName(nickName);
            }
            customerOrBoss1.setScanCount(customerOrBoss1.getScanCount()+1);
            String s = UserTokenManager.generateToken(customerOrBoss1.getId());// 新增用户
            customerOrBoss1.setTransactionalId(scanRecord.getId());
            customerOrBossDao.update(customerOrBoss1);
            map.put("Token",s);
            redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss1),30);
            return Result.ok().setData(map);
        }else {
            CustomerOrBoss customerOrBoss = new CustomerOrBoss();
            customerOrBoss.setOpenId(weiChatDto.getOpenid());
            customerOrBoss.setSessionKey(weiChatDto.getSession_key());
            customerOrBoss.setId(IdUtil.getStringId());
            customerOrBoss.setAddtime(new Date());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss.setNickName(nickName);
            }
            customerOrBoss.setUpdatetime(new Date());
            customerOrBoss.setScanCount(1);
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
            customerOrBoss.setTransactionalId(scanRecord.getId());
            customerOrBossDao.insert(customerOrBoss);
            String s = UserTokenManager.generateToken(customerOrBoss.getId());// 新增用户
            map.put("Token",s);
            redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss),30);
            return Result.ok().setData(map);
        }
    }
    /**
     * boss端无token
     * @param map
     * @param bAuthToken
     * @param code
     * @param flag
     * @param nickName
     * @return
     * @throws Exception
     */
    private Result bossResultNoToken(HashMap map,String bAuthToken, String code, String flag,String nickName) throws Exception {
        HashMap openId = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(code, "", BOSS_APP_ID, BOSS_SECRET));
        if (openId.containsKey("errcode")){
            return Result.ok().setData(openId);
        }
        Object weiChatDto1 = openId.get("weiChatDto");
        Map<String, Object> map2 = JsonXMLUtils.json2map(weiChatDto1.toString());
        WeiChatDto weiChatDto2 = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
        CustomerOrBoss customerOrBoss = customerOrBossDao.queryByOpenId(weiChatDto2.getOpenid());
        if (customerOrBoss != null) {
            customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
            customerOrBoss.setSessionKey(weiChatDto2.getSession_key());
            if (nickName != null && !"".equals(nickName)) {
                customerOrBoss.setNickName(nickName);
            }
            customerOrBoss.setUpdatetime(new Date());
            ScanRecord scanRecord = addShopCustomerRecords(customerOrBoss.getId(), null); // 增加扫码记录
            customerOrBoss.setTransactionalId(scanRecord.getId());
            customerOrBossDao.update(customerOrBoss);
            map.put("bossId",customerOrBoss.getId());
            String s = UserTokenManager.generateToken(customerOrBoss.getId());// 新增用户
            redisUtil.set(s,5,JsonXMLUtils.obj2json(customerOrBoss),30);
            map.put("Token",s);
            return Result.ok().setData(map);
        }else {
            map.put("errorMsg","用户未注册");
            map.put("code",USER_NOT_FOUND);
            return Result.ok().setData(map);
        }
    }

    /**
     * 新增扫码记录
     * 顾客id id
     * @param id 顾客id
     * @param shopId 店铺id
     */
    private ScanRecord addShopCustomerRecords(String id, String shopId) {
        ScanRecord scanRecord = new ScanRecord();
        scanRecord.setId(IdUtil.getStringId());
        scanRecord.setCustomerId(id);
        scanRecord.setShopId(shopId);
        scanRecord.setScanTime(new Date());
        scanRecordDao.insert(scanRecord);
        return scanRecord;
    }
    /**
     * 新增店铺
     * @param customerOrBoss1
     * @param shopInfo
     * @return
     */
    private ShopInfo addShopInfo(CustomerOrBoss customerOrBoss1,ShopInfo shopInfo) {
        shopInfo.setId(IdUtil.getStringId());
        shopInfo.setShopName("店铺的名字");
        shopInfo.setLogoId("http://test.cloudcampusapps.top/wifilink/logo/028b484fcf0a4f19a681f6b9ee1d3d67.png");
        shopInfo.setLogoType(1);
        shopInfo.setMarketingId("http://test.cloudcampusapps.top/wifilink/logo/f1a44db2acc54855b801a617ceda3acf.png");
        shopInfo.setMarketingType(1);
        shopInfo.setSsidFlag(getRandom());
        shopInfo.setStatus(false);
        shopInfo.setAddTime(new Date());
        shopInfo.setUpdateTime(new Date());
        shopInfo.setSsidFlag(getRandom());
        shopInfo.setSsidName("wifi的名字");
        shopInfo.setSsidPassword(getCharAndNumr(8));
        shopInfo.setCustomerOrBossId(customerOrBoss1.getId());
        shopInfo.setState(1);
        shopInfoDao.insert(shopInfo); // 默认生成空的店铺
        ShopInfoReview shopInfoReview = ModelMapperUtil.strictMap(shopInfo, ShopInfoReview.class);
        shopInfoReviewDao.insert(shopInfoReview);
        return shopInfo;
    }
    /**
     * 递归查询缓存中存在验证码
     * @return
     */
    private  String getRandom(){
        String randomNum = CharUtil.getRandomNum(5);
        ShopInfo shopInfo = shopInfoDao.queryBySsIdFlag(randomNum);
        if (shopInfo != null) {
            getRandom();
        }
        return randomNum;
    }
    /**
     * 根据code获取用户信息(暂时弃用)
     * @param code
     * @param flag
     * @return
     */
    @Override
    public Result queryCode(String code, String flag) throws Exception {
        HashMap map = new HashMap();
        String url = "";
        if (flag.equals("1")) {
            return getResult(code, map, url, BOSS_APP_ID, BOSS_SECRET,flag);
        }
        if (flag.equals("2")) {
            return getResult(code, map, url, CUSTOMER_APP_ID, CUSTOMER_SECRET,flag);
        }
        return Result.ok();
    }

    /**
     * (暂时弃用)
     * @param code
     * @param map
     * @param url
     * @param customerAppId
     * @param customerSecret
     * @param flag
     * @return
     * @throws Exception
     */
    private Result getResult(String code, HashMap map, String url, String customerAppId, String customerSecret, String flag) throws Exception {
        HashMap map1 = queryWeiChatService.getOpenId(queryWeiChatService.getUrl(code, url, customerAppId, customerSecret));
        if (map1.containsKey("errcode")){
            return Result.ok().setData(map1);
        }
        Object weiChatDto1 = map1.get("weiChatDto");
        Map<String, Object> map2 = JsonXMLUtils.json2map(weiChatDto1.toString());
        WeiChatDto weiChatDto2 = ModelMapperUtil.strictMap(map2, WeiChatDto.class);
        CustomerOrBoss customerOrBoss = customerOrBossDao.queryByOpenId(weiChatDto2.getOpenid());
        if (customerOrBoss != null) { // 用户存在
            if (flag.equals("2")) {
                customerOrBoss.setScanCount(customerOrBoss.getScanCount()+1);
                customerOrBoss.setSessionKey(weiChatDto2.getSession_key());
                customerOrBossDao.update(customerOrBoss); // 更新扫码次数
                return Result.ok().setData(ModelMapperUtil.strictMap(customerOrBoss, CustomerOrBossDto.class));
            }
                return Result.ok().setData(customerOrBoss.getId());
        }else {
            map.put("errorMsg","用户未注册");
            map.put("code",USER_NOT_FOUND);
            redisUtil.set(code,1, JsonXMLUtils.obj2json(JsonXMLUtils.json2map(map1.get("weiChatDto").toString())),5);
            return Result.ok().setData(map);
        }
    }
}
